#include "widget.h"
#include "ui_widget.h"
#include  "home.h"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
     ui->setupUi(this);
     background_main = new QLabel(ui->tab);
     QPixmap img_1(":/kk/Home/KK_1.png");
     background_main->setPixmap(img_1);
     background_main->setGeometry(ui->tab->rect()); // 填满整个窗口
     background_main->setScaledContents(true);  // 自动拉伸适配窗口大小
     background_main->lower();                  // 将背景设置到最底层


     QLabel *tab_1 = new QLabel;
     QLabel *tab_2 = new QLabel;
     QLabel *tab_3 = new QLabel;

     QPalette palette_1 = tab_1->palette();
     palette_1.setColor(QPalette::Base, Qt::gray); // 设置背景颜色为灰色
     tab_1->setPalette(palette_1);
     tab_1->setAutoFillBackground(true); // 确保背景颜色被应用
     QPalette palette_2 = tab_2->palette();
     palette_2.setColor(QPalette::Base, Qt::gray); // 设置背景颜色为灰色
     tab_2->setPalette(palette_2);
     tab_2->setAutoFillBackground(true); // 确保背景颜色被应用
     QPalette palette_3 = tab_3->palette();
     palette_3.setColor(QPalette::Base, Qt::gray); // 设置背景颜色为灰色
     tab_3->setPalette(palette_3);
     tab_3->setAutoFillBackground(true); // 确保背景颜色被应用
     ui->tabWidget->setStyleSheet("QTabWidget { background: transparent; }");  // 设置 TabWidget 背景透明
     ui->tabWidget->setStyleSheet("QTabBar::tab { background: transparent; }"); // 设置 Tab 标签背景透明
     ui->tabWidget->setStyleSheet("QWidget { background: transparent; }");      // 设置 Tab 页内容背景透明
     QPixmap kk_i(":/kk/KK/Music.jpg");
     ui->label_2->setPixmap(kk_i);

     QMovie *kk_gif = new QMovie(":/kk/KK/kk1.gif");
     ui->label_5->setMovie(kk_gif);
     kk_gif->start();
     // 隐藏 QTabBar
     ui->tabWidget->tabBar()->setVisible(false);
     widget_1 *Tab_1 = new  widget_1(this);
     ui->tabWidget->addTab(Tab_1,"音乐播放");


     widget_2 *Tab_2 = new  widget_2(this);
     ui->tabWidget->addTab(Tab_2,"天气预报");

     home *Tab_3= new  home(this);
     ui->tabWidget->addTab(Tab_3,"智能家居");
      ui->tabWidget->setCurrentIndex(4);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_Button_tab1_clicked()
{
    ui->tabWidget->setCurrentIndex(0);
}

void Widget::on_Button_tab2_clicked()
{
    ui->tabWidget->setCurrentIndex(2);
    QPixmap kk_i(":/kk/KK/Music.jpg");
    ui->label_2->setPixmap(kk_i);

    QMovie *kk_gif = new QMovie(":/kk/KK/kk1.gif");
    ui->label_5->setMovie(kk_gif);
    kk_gif->start();
   // ui->label_5->setGeometry(this->rect()); // 填满整个窗口

}



void Widget::on_tabWidget_currentChanged(int index)
{
   //widget_1 w2(this->tabWidget)
}

void Widget::on_Button_tab3_clicked()
{
    ui->tabWidget->setCurrentIndex(3);
}

void Widget::on_pushButton_clicked()
{
    ui->tabWidget->setCurrentIndex(4);
}
